package info.itest.www.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import info.itest.www.pages.*;

public class LoginPage extends BasePage {
	
	public LoginPage(WebDriver dr,String url){
		super(dr);
		this.url = url;
		this.goTo();
	}
	
	By usernameLocator = By.id("user_login");
	By passwordLocator = By.id("user_pass");
	By loginButtonLocator = By.id("wp-submit");
	By loginErrorLocator = By.id("login_error");
	
	public WebElement getUserTextField(){
		return this.dr.findElement(usernameLocator);
	}
	
	public WebElement getPasswordField(){
		return this.dr.findElement(passwordLocator);
	}
	
	public WebElement getSubmitButton(){
		return this.dr.findElement(loginButtonLocator);
	}
	
	public WebElement getLoginErrorDiv(){
		return this.dr.findElement(loginErrorLocator);
	}
	
	public DashPage login(String username,String password){
		
		this.doLoginStep(username,password);
		return new DashPage(this.dr);
		}
	
	public LoginPage loginFailed(String username,String password){
		this.doLoginStep(username, password);
		return this;
	}
	
	private void doLoginStep(String username,String password){
		this.getUserTextField().sendKeys(username);
		this.getPasswordField().sendKeys(password);
		this.getSubmitButton().click();
	}
	
}
